<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class group extends MY_Controller {
	function __construct(){
		parent::__construct();
		if(!$this->ion_auth->in_group("admin")){
			show_404();
		}
	}

	function admin_index(){
		$result = $this->ion_auth->groups()->result_array();
		$this->_assign("groups", $result);
		$this->_fetch('admin_index');
	}

	function admin_add($id = NULL){
		if(!empty($id)){
			$group = $this->ion_auth->group($id)->result_array();
		  $this->_assign('group', $group);
		  $this->_fetch('admin_add');
		}else{
			$_post = $this->input->post();
			if(!empty($_post["submit"]) AND !empty($_post['name'])){
				if($_post["id"]){
					$this->ion_auth->update_group($_post["id"],$_post["name"],$_post["description"]);
				}else{
					$this->ion_auth->create_group($_post["name"],$_post["description"]);
				}
				redirect(base_url('admin/group'));
			}else{
				$this->_fetch('admin_add');
			}
		}
	}

	function admin_delete($id=""){
		$this->ion_auth->delete_group($id);
		redirect(base_url('admin/group'));
	}

}